<template>
  <div class="containt">
    <nav-com title="" :showView="true" @back="backHandler()"></nav-com>
    <div style="margin: 0 20px;margin-top: 25vh;">
        <div style="margin: 0 20px;line-height: 40px;font-weight: 600;margin-top: 10px;color: #222222;"><span style="color:red">*</span>姓名:</div>    
        <van-cell-group inset>
        <van-field v-model="formData.name" placeholder="请输入你的姓名" />
        </van-cell-group>
        <div style="margin: 0 20px;line-height: 40px;font-weight: 600;margin-top: 10px;color: #222222;"><span style="color:red">*</span>手机号:</div>    
        <van-cell-group inset>
        <van-field v-model="formData.mobile" placeholder="请输入你的手机号" />
        </van-cell-group>
        <div style="margin: 0 20px;line-height: 40px;font-weight: 600;margin-top: 10px;color: #222222;">地址:</div>    
        <van-cell-group inset>
        <van-field v-model="formData.address" placeholder="(选填)请输入你的地址" />
        </van-cell-group>
        <div style="margin: 0 20px;line-height: 40px;font-weight: 600;margin-top: 10px;color: #222222;">推荐人手机号:</div>    
        <van-cell-group inset>
        <van-field v-model="formData.reg_mobile" placeholder="(选填)请输入推荐人手机号" />
        </van-cell-group>
        <div style="margin: 0 20px;line-height: 40px;font-weight: 600;margin-top: 10px;color: #222222;">缴纳联创伙伴定金:</div>    
        <van-cell-group inset >
        <van-field type="digit" @blur="moneyHandler" readonly v-model="formData.money" placeholder="2000"  @click-right-icon="showPipupClick">
            <!-- <van-icon   size="20" slot='right-icon' name="arrow-down" ></van-icon> -->
        </van-field>
        </van-cell-group>
        <div style="margin: 0 20px;font-size:12px;color:#FF6932;line-height: 30px;font-weight: bold;">备注：要缴纳的联创伙伴定金金额必须≧2000</div>

        <div style="width: 80vw;
        line-height: 45px;
        text-align: center;
        color: #fff;
        background: #2A6BEF;
        margin: auto;
        margin-top: 10px;
        border-radius: 4px;" @click="submit">申请</div>
    </div>
    <van-popup v-model="showPipup" position="bottom">
            <van-picker show-toolbar :columns="columns" 	 @confirm="onConfirm" @cancel="showPipup = false"></van-picker>
     </van-popup>
  </div>
</template>
  
  <script>
import navCom from "@/component/nav";
import { unionAdd } from "@/api/api.js";
import { Field, CellGroup,Picker,Icon,Toast} from 'vant';
export default {
  components: {
    navCom,
  },
  data() {
    return {
      dataInfo: {},
      showPipup:false,
      value:"",
      columns:['2000'],
      formData:{
        name:"",
        mobile:"",
        address:"",
        money:"2000",
        reg_mobile:""
      }
    };
  },
  created() {
    
  },
  methods: {
    moneyHandler(e){
      console.log(e.target.value);
      if(e.target.value<2000){
        Toast("定金金额必须≧2000");
        this.formData.money=2000;
      }
    },
    showPipupClick(){
         console.log("showPipupClick");
         this.showPipup=true;
    },
    onConfirm(e){
        console.log("onConfirm",e)
        this.formData.money=e;
        this.showPipup=false;
    },
    goPage(type) {
      if (type == 1) {
        this.$router.push("/toFuture");
      }
      if (type == 2) {
        this.$router.push("/togetherInvitatio");
      }
    },
    //返回
    backHandler() {
      this.$router.go(-1);
      // if (weixin.isAndroid()) {
      //   window.JS_TROOPS.goBack();
      // } else {
      //   this.$router.go(-1);
      // }
    },
    // 初始化数据
    submit() {
        if(this.formData.name==""){
          Toast("请输入姓名");
          return;
        }
        if(this.formData.mobile==""){
          Toast("请输入手机号");
          return;
        }
        unionAdd(this.formData)
        .then((res) => { 
          console.log("unionAdd",res);
          if (res.data.code == 1) {
              Toast(res.data.msg);
              this.backHandler()
          }
          if(res.data.msg.indexOf("余额不足")!=-1){
            this.$dialog
          .alert({
            title: "提示",
            message:
              "余额不足，请先充值",
            showCancelButton: true,   
            confirmButtonText: "去充值",
          })
          .then(() => {
            this.$router.push("/recharge");
          });
          }else{
            Toast(res.data.msg);
          }
         
        
        })
        .catch((err) => {});
    },
  },
};
</script>
  
<style scoped>
.containt {
  min-height: 885px;
  /* height: auto; */
  background: #f2f3f7;
  background-image: url('../../../assets/my/togetherInvitationBG.png');
  background-repeat: round;
}


</style>
<style scoped>
/deep/  .back_box {
  background-color: transparent !important;
  width: 100vw;
  height: 13.33vw;
  line-height: 13.33vw;
  -webkit-box-shadow: 0px 0px 6px 0px transparent !important;
  box-shadow: 0px 0px 6px 0px transparent !important;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
}

/deep/ .van-cell {
    background-color: #F8F7F7!important;
}
</style>